/*
 * @author Steve Cox
 * @date 10/20/2011
 * @description Unit tests for MM_ImplantMedicalCenterController
 */
@isTest
private class MM_ImplantMedicalCenterControllerTests {
   static testMethod void test() {
      // create a patient and supporting objects
      Account hospital = MM_Test.newHospital();
      insert hospital;
      
      Contact surgeon = MM_Test.newSurgeon();
      insert surgeon;
      
      Patient__c patient = MM_Test.newPatient(hospital.Id);
      insert patient;

      Implant__c implant = MM_Test.newImplant(patient.Id);

      Test.startTest();
      // construction
      ApexPages.StandardController standardController = 
         new ApexPages.StandardController(patient);
      MM_ImplantMedicalCenterController controller = 
         new MM_ImplantMedicalCenterController(standardController);

      // form page label
      System.assert(controller.getFormPage().length() > 0);
      
      // implants
      System.assert(0 == controller.implants.size());
      insert implant;
      controller = new MM_ImplantMedicalCenterController(standardController);
      System.assert(1 == controller.implants.size());
      
      // save
      controller.implantList[0].implant.Surgeon__c = hospital.Id;
      try {
         controller.save();
         System.assert(false, 'invalid data saved');
      } catch (DMLException e) {
      }
 
      controller.implantList[0].implant.Surgeon__c = surgeon.Id;
      controller.save();
      System.assertEquals(surgeon.id, controller.implantList[0].implant.Surgeon__c);

      // cancel
      controller.implantList[0].implant.Surgeon__c = hospital.Id;
      controller.cancel();
      System.assertNotEquals(hospital.Id, controller.implantList[0].implant.Surgeon__c);
      
      Test.stopTest();
   }
}